Skip to content

Add admin protection error message for shadow admin scenarios#40170

Open
benhillis wants to merge 3 commits intomasterfrom
user/benhill/admin_protection
Open

Add admin protection error message for shadow admin scenarios#40170
benhillis wants to merge 3 commits intomasterfrom
user/benhill/admin_protection

Conversation

@benhillis
Copy link
Copy Markdown
Member

When Windows Admin Protection is enabled, the elevated process runs as a shadow admin with a different SID, so distributions registered under the real user are not visible.

This adds an informational message explaining Admin Protection in two cases:

  1. Launching a distribution by name that is not found (WSL_E_DISTRO_NOT_FOUND)
  2. Listing distributions when none are registered (WSL_E_DEFAULT_DISTRO_NOT_FOUND)

The message links to https://aka.ms/apdevguide for more details.

@benhillis benhillis requested a review from a team as a code owner April 13, 2026 16:37
Copilot AI review requested due to automatic review settings April 13, 2026 16:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds clearer user-facing guidance for “shadow admin” scenarios when Windows Admin Protection causes WSL distributions to appear missing under the elevated token.

Changes:

  • Adds Admin Protection-aware messaging when a named distro isn’t found and when no distros are registered.
  • Introduces IsAdminProtectionEnabled() helper in WslSecurity that detects shadow admin mode via a dynamically loaded API.
  • Adds a new localized string resource for the Admin Protection informational message.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/windows/service/exe/LxssUserSession.cpp Attempts to surface an Admin Protection info message when a requested distro name can’t be found.
src/windows/common/wslutil.cpp Extends GetErrorString() to prepend Admin Protection info when no default distro is found.
src/windows/common/WslSecurity.h Declares new IsAdminProtectionEnabled() API.
src/windows/common/WslSecurity.cpp Implements Admin Protection detection (elevation + dynamically loaded shadow admin check).
localization/strings/en-US/Resources.resw Adds MessageAdminProtectionEnabled localized string.

Comment thread src/windows/service/exe/LxssUserSession.cpp Outdated
Comment thread src/windows/common/wslutil.cpp Outdated
Comment thread src/windows/common/WslSecurity.cpp Outdated
Comment thread src/windows/common/WslSecurity.cpp Outdated
@benhillis benhillis force-pushed the user/benhill/admin_protection branch from 4824178 to 424f4dc Compare April 13, 2026 17:05
Copilot AI review requested due to automatic review settings April 13, 2026 17:28
@benhillis benhillis force-pushed the user/benhill/admin_protection branch from 424f4dc to 8bcabe1 Compare April 13, 2026 17:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/windows/common/wslutil.cpp Outdated
Comment thread src/windows/common/wslutil.cpp
Comment thread localization/strings/en-US/Resources.resw Outdated
Ben Hillis added 2 commits April 13, 2026 12:51
When Windows Admin Protection is enabled, the elevated process runs as a
shadow admin with a different SID, so distributions registered under the
real user are not visible. Surface an informational message in two cases:

1. Launching a distribution by name that is not found (WSL_E_DISTRO_NOT_FOUND)
2. Listing distributions when none are registered (WSL_E_DEFAULT_DISTRO_NOT_FOUND)
Copilot AI review requested due to automatic review settings April 13, 2026 19:55
@benhillis benhillis force-pushed the user/benhill/admin_protection branch from 5951c58 to 84407b1 Compare April 13, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/windows/common/wslutil.cpp
OneBlue
OneBlue previously approved these changes Apr 13, 2026
bool IsAdminProtectionEnabled()
{
const auto token = wil::open_current_access_token();
if (!wsl::windows::common::security::IsTokenElevated(token.get()))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OneBlue - Perhaps we should return this error in both cases? (even non-admin)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only apply in the case where the user is elevated right ? If the other was not found and the user was non-elevated, then we know for sure that it's a user error, so probably best not to display this imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants